<template>
  <div>
    <label>请选择题目类型</label>
    <template>
      <el-select v-model="type" placeholder="请选择">
        <el-option
          v-for="(item, index) in options"
          :key="item.value"
          :label="item.label"
          :value="index + 1"
        >
        </el-option>
      </el-select>
    </template>
    <label>请选择科目</label>
    <template>
      <el-select v-model="sub" placeholder="请选择">
        <el-option
          v-for="(item, index) in subject"
          :key="item.value"
          :label="item.label"
          :value="index + 1"
        >
        </el-option>
      </el-select>
    </template>

    <label>指定教师</label>
    <template>
      <el-select v-model="tea" placeholder="请选择">
        <el-option
          v-for="item in teacher"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </template>

    <h3>请输入问题描述</h3>
    <el-input
      type="textarea"
      :autosize="{ minRows: 20, maxRows: 22 }"
      placeholder="请输入内容"
      v-model="context"
    >
    </el-input>
    <el-button type="primary" style="margin-top:10px;margin-left:10%"
      >取消</el-button
    ><span>
      <el-button
        type="primary"
        style="margin-top:10px;margin-left:60%"
        @click="submitquestion"
        >提交</el-button
      >
    </span>
  </div>
</template>

<script>
import axios from "axios";
import commons from "../../assets/commons";
export default {
  data() {
    return {
      //将内容封装成一个类
      question_ask: {},
      //具体内容
      context: "",
      options: [
        {
          value: "选择题",
          label: "选择题"
        },
        {
          value: "填空题",
          label: "填空题"
        },
        {
          value: "解答题",
          label: "解答题"
        },
        {
          value: "作文题",
          label: "作文题"
        }
      ],
      type: "", //题目类型
      subject: [
        {
          value: "语文",
          label: "语文"
        },
        {
          value: "数学",
          label: "数学"
        },
        {
          value: "英语",
          label: "英语"
        },
        {
          value: "政治",
          label: "政治"
        },
        {
          value: "历史",
          label: "历史"
        },
        {
          value: "地理",
          label: "地理"
        },
        {
          value: "物理",
          label: "物理"
        },
        {
          value: "化学",
          label: "化学"
        },
        {
          value: "生物",
          label: "生物"
        }
      ],
      sub: "",
      teacher: [
        {
          value: "小杨",
          label: "小杨"
        },
        {
          value: "大杨",
          label: "大杨"
        },
        {
          value: "啊杨",
          label: "啊杨"
        }
      ],
      tea: ""
    };
  },
  methods: {
    submitquestion() {
      this.question_ask.type = this.type;
      this.question_ask.subject = this.sub;
      this.question_ask.tea_name = this.tea;
      this.question_ask.context = this.context;
      this.question_ask.u_id = this.$store.state.userid;
      this.question_ask.upload_time = new Date();
      this.question_ask.state = 1;
      axios
        .post(commons.baseUrl + "student/insertquestion", this.question_ask, {
          headers: { "Content-Type": "application/JSON" }
        })
        .then(res => {

          if (res.data.code == 200) {
            alert(res.data.message);
            (this.type = ""),
              (this.sub = ""),
              (this.tea = ""),
              (this.context = "");
          } else {
            alert(res.data.message);
          }
        });
    }
  }
};
</script>
<style scoped></style>
